var util = require("../../utils/util.js");
Page({
    data: {
        loaddingHidden: true,
        date: new Date().Format("yyyy-MM-dd"),
        index: 0,
        websitenum: '请选择销售人员的网点'
    },
    task_add: function() {
        wx.redirectTo({
            url: '../WebSiteLoop_Task/WebSiteLoop_Task'
        })
    },

    task_lists: function() {
        wx.redirectTo({
            url: '../TaskList/TaskList'
        })
    },
    bindDateChange: function(e) {
        this.setData({
            date: e.detail.value
        })
    },
    selectWebSite: function(e) {
        var that = this;
        var TaskExecutorAccout = this.data.list[this.data.index].MemberNo;
        wx.navigateTo({
            url: '../select_webSite/select_webSite?TaskExecutorAccout=' + TaskExecutorAccout + '&index=' + that.data.index + '&title=' + that.data.title + '&msg=' + that.data.msg + '&date=' + that.data.date
        })
    },
    onLoad: function(options) {
        var that = this;
        that.setData({ loaddingHidden: !that.data.loaddingHidden })
        var websiteid = options.websiteid;
        var index = options.index;
        if (index) {
            that.setData({ index: index })
        }
        var title = options.title
        if (title)
            that.setData({ title: title })
        else
            that.setData({ title: '' })
        var msg = options.msg
        if (msg)
            that.setData({ msg: msg })
        else
            that.setData({ msg: '' })
        var date = options.date
        if (date)
            that.setData({ date: date })

        if (websiteid) {
            websiteid = websiteid.substring(1);
            var websiteids = websiteid.split(",");
            that.setData({ websitenum: websiteids.length + "个" })
            that.setData({ websiteid: websiteid.replace(/end/g, "") })
        }
        var url = getApp().globalData.mainUrl + "WX_MiniApps_HR_GetAccountList.ashx";
        var OpenID = wx.getStorageSync("OpenID");
        var Token = wx.getStorageSync("Token");
        wx.request({
            url: url,
            data: {
                OpenID: OpenID,
                Token,
                Token
            },
            success: function(res) {
                that.setData({ loaddingHidden: !that.data.loaddingHidden })
                console.log(res)
                var list = new Array();
                var list1 = new Array();
                res.data.ReturnData.forEach(function(obj, index) {
                    list[index] = {
                        MemberID: obj.MemberID,
                        MemberNo: obj.Accout,
                        Name: obj.AccoutName
                    }
                    list1[index] = obj.AccoutName;
                });
                console.log(list1)
                that.setData({ list: list, list1: list1 })
            }
        })
    },
    bindPickerChange: function(e) { //选人员
        this.setData({ index: e.detail.value })
    },
    bindTitleChnage: function(e) {
        this.setData({ title: e.detail.value });
    },
    bindMsgChange: function(e) {
        this.setData({ msg: e.detail.value });
    },
    reserveSubmit: function() {
        var that = this;
        that.setData({ loaddingHidden: !that.data.loaddingHidden })
        var OpenID = wx.getStorageSync("OpenID");
        var Token = wx.getStorageSync("Token");
        var TaskTitle = this.data.title;
        var TaskExecutorAccout = this.data.list[this.data.index].MemberNo;
        var TaskExecutorDate = this.data.date;
        var WebSiteIDList = this.data.websiteid;
        var Note = this.data.msg;
        var url = getApp().globalData.mainUrl + "WX_MiniApps_WebSite_AddTask.ashx";
        wx.request({
            url: url,
            data: {
                Token: Token,
                OpenID: OpenID,
                TaskTitle: TaskTitle,
                TaskExecutorAccout: TaskExecutorAccout,
                TaskExecutorDate: TaskExecutorDate,
                WebSiteIDList: WebSiteIDList,
                Note: Note
            },
            success: function(res) {
                that.setData({ loaddingHidden: !that.data.loaddingHidden })
                console.log(res.data)
                wx.showModal({
                        content: res.data.ReturnMsg
                    })
                    // }
            }
        });
    }
})